<template>
	<view>
		<my_search></my_search>
		<!--商品列表 -->
		<view class="commodity_box">
			<!-- 左侧滚动区域 -->
			<scroll-view scroll-y="true" class="left_scroll_box" :style="{height: wh + 'px'}">
				<view v-for="(item,i) in scrollData" :key="i" :class="[i === active ? 'active' : '']" @click="changeSele(i)">
					<text>{{item.cat_name}}</text>
				</view>
			</scroll-view>
			<!-- 右侧滚动区域 -->
			<scroll-view scroll-y="true" class="right_scroll_box" :style="{height: wh + 'px'}">
				<view class="srcoll_list">
					<block v-for="(item, i) in subScroll" :key="i">
						<view class="sub_tit">{{item.cat_name}}</view>
						<view class="srcoll_item" v-for="(item2, i2) in item.children" :key="i2">
							<view class="tit"><text>{{item2.cat_name}}</text></view>
							<image :src="item2.cat_icon" mode=""></image>
						</view>
					</block>
				</view>
			</scroll-view>
		</view>
		
		<tab-bar></tab-bar>
	</view>
</template>

<script>
import subsection from '../../uni_modules/uview-ui/libs/config/props/subsection'
	export default {
		data() {
			return {
				active: 0, // 选中的标签
				wh: 0, // scroll高度
				scrollData: [], // 列表所有数据
				subScroll:[] // 二级列表
			}
		},
		onLoad() {
			const uh = uni.getWindowInfo()
			this.wh = uh.windowHeight - 40
			this.getCommodityList()
		},
		methods: {
			async getCommodityList(){
				const {data: res} = await uni.$http.get('/api/public/v1/categories')
				this.scrollData = res.message
				this.subScroll = this.scrollData[0].children
				// console.log(this.subScroll)
			},
				
			changeSele(e){
				this.active = e
				this.subScroll = this.scrollData[e].children
			}
		}
	}
</script>

<style lang="scss">
	page{background-color: #ffffff;}
	.commodity_box .left_scroll_box{width: 30%;float: left;}
	.commodity_box .left_scroll_box view{
		background-color: #eeeeee;
		height: 60px;
		line-height: 60px;
		font-size: 22rpx;
		text-align: center;
		&.active{
			background-color: white;
			position: relative;
			&:before{
				content: '';
				width: 5px;
				height: 50%;
				border-radius: 10px;
				background-color: rebeccapurple;
				position: absolute;
				left: 0;
				top: 0;
				bottom: 0;
				margin: auto;
			}
		}
	}
	.commodity_box .right_scroll_box{width: 70%;float: left;}
	.commodity_box .right_scroll_box .srcoll_list{
		width: 90%; 
		margin: 30rpx auto 0;
		overflow: hidden;
		.sub_tit{
			text-align: center;
			font-weight: bold;
			font-size: 30rpx;
		}
	}
	.commodity_box .right_scroll_box .srcoll_item{
		/* width: 100%; */
		height:  400rpx;
		font-size: 25rpx;
		text-align: center;
		margin-bottom: 40rpx;
		.tit{
			display: block;
			text-align: left;
			position: relative;
			text-align: center;
			margin: 20rpx 0;
			text{
				background-color: #ffffff;
				padding: 0 20rpx;
				position: relative;
				z-index: 1;
			}
			&:after{
				content: '';
				width: 100%;
				height: 1rpx;
				background-color: #eee;
				position: absolute;
				right: 0;
				top: 0;
				bottom: 0;
				margin: auto;
			}
		}
		image{
			border-radius: 20rpx;
			height: 350rpx;
			width: 95%;
			border: #eee solid 1rpx;
			display: inline-block;
		}
	}
</style>
